package org.hefan.hrm.service.impl;

import org.hefan.hrm.client.LoginUserClient;
import org.hefan.hrm.domain.Employee;
import org.hefan.hrm.domain.Tenant;
import org.hefan.hrm.mapper.EmployeeMapper;
import org.hefan.hrm.service.IEmployeeService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.hefan.hrm.vo.UserContextInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author HeFan
 * @since 2022-01-02
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {

    @Autowired
    private LoginUserClient loginUserClient;

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public UserContextInfo getEmpAndTenantByLoginId(Long loginId) {
        //查看员工及租户信息
        Employee employee = employeeMapper.loadEmpAndTenantByLoginId(loginId);
        //封装为要返回UserContextInfo
        UserContextInfo userContextInfo = new UserContextInfo();
        userContextInfo.setEmployeeId(employee.getId());
        userContextInfo.setEmpUsername(employee.getUsername());
        Tenant tenant = employee.getTenant();
        if (tenant != null) {
            userContextInfo.setTenantId(tenant.getId());
            userContextInfo.setTenantName(tenant.getCompanyName());
        }
        return userContextInfo;
    }
}
